package it.xiuxian.homepage.activity

import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import it.xiuxian.homepage.R
import it.xiuxian.homepage.bean.Detail
import it.xiuxian.homepage.databinding.HomepageZixunActivityBinding
import it.xiuxian.homepage.fragment.ZiXunFragment
import it.xiuxian.homepage.presenter.ZiXunActivityPresenter
import it.xiuxian.lib.base.*
import it.xiuxian.lib.utils.*
import it.xiuxian.lib.utils.adapter.SlimAdapter
import it.xiuxian.lib.utils.adapter.SlimInjector
import it.xiuxian.lib.utils.adapter.injector.IViewInjector
import it.xiuxian.swindle.adapter.MyFragmentAdapter
import kotlinx.android.synthetic.main.homepage_head.view.*
import kotlinx.android.synthetic.main.homepage_zixun_activity.view.*
import java.util.*

@Route(path = ArouterAddress.ZIXUNACTIVITY)
class ZiXunActivity:BaseActivity<ZiXunActivityPresenter>(){
    @JvmField
    @Autowired
    var erweima:String?="zhangsan"
   lateinit var binding: HomepageZixunActivityBinding
    lateinit var fragments: ArrayList<Fragment>
   // lateinit var adapter1: SlimAdapter
    override val layoutId: Int
        get() = R.layout.homepage_zixun_activity
    override val presenter: ZiXunActivityPresenter
        get() = ZiXunActivityPresenter()

    override fun initView(){
        ARouter.getInstance().inject(this)
        binding= getViewDataBinding<HomepageZixunActivityBinding>()
        (binding.include.re.layoutParams as LinearLayout.LayoutParams).setMargins(0,DensityUtil.getStatusPix(
            App.INSTANCE.applicationContext)+5,0,0)
        setTitle("公益日记")
        initTab()
      //  initAdapter()

    }

    private fun initAdapter(){

    }

    private fun initTab() {
        fragments = ArrayList()
        val titles:Array<String> = arrayOf("最新","最热")
        LiveDataBus.get().with(RxBusCode.ZIXUNFINISHLOAD).observe(this, Observer {
            getCode()
        })
        erweima = SPUtil.get("erweima","")
        fragments.add(ARouter.getInstance().build(ArouterAddress.ZIXUNFRAGMENT).withString("erweima",erweima).withString("flag","1").navigation() as ZiXunFragment)
        fragments.add(ARouter.getInstance().build(ArouterAddress.ZIXUNFRAGMENT).withString("erweima",erweima).withString("flag","2").navigation() as ZiXunFragment)
        binding.viewpager.adapter= MyFragmentAdapter(supportFragmentManager,fragments)
        binding.tab.setViewPager(binding.viewpager,titles)
        binding.tab.currentTab = 1
        binding.tab.isTabSpaceEqual = false
        binding.tab.setIndicatorWidthEqualTitle(false)
        binding.tab.textsize = 50f
        binding.tab.textBold = 2
        binding.tab.setUnderlineGravity(Gravity.BOTTOM)
        binding.tab.indicatorColor =resources.getColor(R.color.red_1)
        binding.tab.indicatorWidth = 20f
        binding.tab.textSelectColor = resources.getColor(R.color.black)
        binding.tab.textUnselectColor=resources.getColor(R.color.libTextGray)
        binding.tab.setOnTabSelectListener(object : HeySlidingTabLayout.OnTabSelectListener{
            override fun onTabSelect(position: Int): Boolean {
                binding.viewpager.currentItem = position
                return false
            }

            override fun onTabReselect(position: Int) {

            }

        })
    }

    override fun initEvent(){
        binding.smart.setOnRefreshListener {
            mPresenter!!.getList("1","1")
         /* var s=  AppManager.activitystack
            Log.e("WangJ",s.toString())*/
          //  LogUtils.e(s.toString(),Throwable())
            LiveDataBus.get().with(RxBusCode.ZIXUNREFRESH).postValue(1988)
            binding.smart.finishRefresh()
        }
        binding.smart.setOnLoadMoreListener {
            LiveDataBus.get().with(RxBusCode.ZIXUNLOADMORE).postValue(1989)
        }
    }

       fun getCode(){
            binding.smart.finishLoadMore()
        }
    override fun initData() {
        //mPresenter!!.getList("1","1")
    }
    fun geData(list: List<Detail>){
       // adapter1.updateData(list)
    }
}